/* * wybrane przykłady.c * * * Created by Leszek on 13-04-19. * Copyright 2013 __MyCompanyName__. All rights reserved. * */ interrups: //Deklaracja przerwaÒ ******************************************************************************* // test pio - strona 237 // funkcja obs≥ugi przerwania: #ifndef NIE_DODAWAJ_PRZERWAN_PRZYCISKOW #include "system.h" #include "altera_avalon_pio_regs.h" #include "alt_types.h" static void handle_button_interrupts(void* context, alt_u32 id) { /* cast the context pointer to an integer pointer. */ volatile int* edge_capture_ptr = (volatile int*) context; INT8U error; /* * Read the edge capture register on the button PIO. * Store value. */ *edge_capture_ptr = IORD_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE); /* Write to the edge capture register to reset it. */ IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0); /* reset interrupt capability for the Button PIO. */ IOWR_ALTERA_AVALON_PIO_IRQ_MASK(BUTTON_PIO_BASE, 0xf); error=OSSemPost(SemaforPrzyciskow); switch(error){ case OS_NO_ERR: printf("Przerwanie: semafor podniesiony poprawnie\n"); break; case OS_SEM_OVF: printf("Przerwanie: semafor zosta≥ zwrÛcony wiÍcej razy niø pobrany\n"); break; case OS_ERR_EVENT_TYPE: printf("Przerwanie: pevent nie jest semaforem\n"); break; case OS_ERR_PEVENT_NULL: printf("Przerwanie: pevent==NULL\n"); break; } printf("Przerwanie: edge_capture_ptr=%d\n", *edge_capture_ptr); } // rejestracja przerwania w programie g≥Ûwnym #include "sys/alt_irq.h" #include "system.h" /* Declare a global variable to hold the edge capture value. */ volatile int edge_capture; /* Initialize the button_pio. */ static void init_button_pio() { /* Recast the edge_capture pointer to match the alt_irq_register() function prototype. */ void* edge_capture_ptr; //void* edge_capture_ptr = (void*) &edge_capture; edge_capture_ptr = (void*) &edge_capture; /* Enable all 4 button interrupts. */ IOWR_ALTERA_AVALON_PIO_IRQ_MASK(BUTTON_PIO_BASE, 0xf); /* Reset the edge capture register. */ IOWR_ALTERA_AVALON_PIO_EDGE_CAP(BUTTON_PIO_BASE, 0x0); /* Register the ISR. */ alt_irq_register( BUTTON_PIO_IRQ, edge_capture_ptr, handle_button_interrupts ); } #endif //MemoryPartition: OS_MEM *PamiecDeskryptorowTCP; struct DeskryptorTCP des_TCP[ILOSC_DESKRYPTOROW_TCP]; PamiecDeskryptorowTCP = OSMemCreate(&des_TCP[0], ILOSC_DESKRYPTOROW_TCP, sizeof(struct DeskryptorTCP), &error); printf("sizeof(struct DeskryptorTCP): %lu; sizeof(PamiecDeskryptorowTCP): %lu\n", sizeof(struct DeskryptorTCP), sizeof(PamiecDeskryptorowTCP)); switch(error){ case OS_NO_ERR: printf("DeskryptoryTCP: OK \n"); break; case OS_MEM_INVALID_ADDR: printf("DeskryptoryTCP: niepoprawny adres \n"); break; case OS_MEM_INVALID_PART: printf("DeskryptoryTCP: brak wolnej pamiÍci \n"); break; case OS_MEM_INVALID_BLKS: printf("DeskryptoryTCP: za ma≥o zadeklarowanych deskryptorÛw (min. 2) \n"); break; case OS_MEM_INVALID_SIZE: printf("DeskryptoryTCP: rozmiar memory partition jest za ma≥y, øeby pomieúciÊ wskaünik \n"); break; }